# Maintainer: Sarah Ottinger <schalaalexiazeal@gmail.com>
# Contributor: Miloš Komarčević <miloskomarcevic@aim.com>

_realname=imageio
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=2.10.1
pkgrel=1
pkgdesc="Python library for reading and writing a wide range of image, video, scientific, and volumetric data formats (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url='https://github.com/imageio/imageio'
license=('BSD-2-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-python-numpy"
         "${MINGW_PACKAGE_PREFIX}-python-pillow")
optdepends=("${MINGW_PACKAGE_PREFIX}-freeimage"
            "${MINGW_PACKAGE_PREFIX}-python-tifffile")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
options=('staticlibs' 'strip' '!debug')
source=("${_realname}-${pkgver}.tar.gz"::"${url}/archive/v${pkgver}.tar.gz")
sha256sums=('43eefc54146c42d95c8212150216f952c4e6e8270d58b6e01118348aa2c0e252')

prepare() {
  cd "${srcdir}"

  rm -rf python-build-${MINGW_ARCH} || true
  cp -r "${_realname}-${pkgver}" "python-build-${MINGW_ARCH}"
}

build() {
  msg "Python build for ${MINGW_ARCH}"  
  cd "${srcdir}/python-build-${MINGW_ARCH}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

check() {
  msg "Python test for ${MINGW_ARCH}"
  cd "${srcdir}/python-build-${MINGW_ARCH}"
  ${MINGW_PREFIX}/bin/python setup.py check --strict
}

package() {
  cd "${srcdir}/python-build-${MINGW_ARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"

  # remove shebang line
  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*-script.py; do
    sed -e '1 { s/^#!.*$// }' -i ${_f}
  done

  # remove utilities for downloading binary dependencies
  rm -rf $pkgdir/${MINGW_PREFIX}/bin
}
